<?php
// +----------------------------------------------------------------------
// | DTPHP 
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://dtphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yyj <qingchen.yyj@gmail.com>
// +----------------------------------------------------------------------


namespace app\doc\controller;


use doc\ApiDoc;
use doc\BootstrapApiDoc;
use ReflectionClass;
use Swagger\Annotations\Swagger;

/**
 * Class Doc
 * @package app\doc\controller
 * 接口文档生成
 *
 */
class Doc
{
    public function index()
    {
        $dirname = explode('application', __DIR__)[0] . 'application';
        $config = [
            'class' => $this->bl_scandir($dirname), // 要生成文档的类
            'filter_method' => ['__construct'], // 要过滤的方法名称
        ];
        $api = new BootstrapApiDoc($config);
        exit($api->getHtml());

    }

    function bl_scandir($dirname)
    {
        $classNames = [];
        $dirArr = scandir($dirname);
        foreach ($dirArr as $v) {
            //组合文件或文件夹的路径
            $filename = $dirname . '/' . $v;
            if ($v != '.' && $v != '..') {
                if (is_dir($filename)) {
                    $classNames = array_merge($classNames, $this->bl_scandir($filename));
                } else {
                    if (substr_count($filename, '/controller/')) {
                        $className = str_replace('.php', '', str_replace('/', '\\', 'app' . explode('application', $filename)[1]));
                        array_push($classNames, $className);
                    }
                }
            }
        }
        return $classNames;
    }

}